//
//  XS_LoginThreeVC.swift
//  XueDao
//
//  Created by 韩云智 on 2021/1/7.
//

import UIKit

class XS_LoginThreeVC: XS_BaseVC {
    
    var openid: String?
    var iosid: String?

    override func upConfig() {
        isStatusBarBlack = false
        shouldNavBarHidden = true
    }
    override func upView() {
        let imgV = UIImageView(image: UIImage(named: "位图 + 矩形 蒙版"))
        view.addSubview(imgV)
        imgV.snp.makeConstraints { m in
            m.edges.equalToSuperview()
        }
        loadCustomBar()
        
        do {
            let tLab = UILabel.xsLabel(size: .scale*26, fontName: .semibold, color: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), text: "绑定手机号")
            view.addSubview(tLab)
            tLab.snp.makeConstraints { m in
                m.left.equalTo(.scale*40)
                m.top.equalTo(.barHeight + .scale*76)
            }
            
//            let dLab = UILabel.xsLabel(size: .scale*16, fontName: .regular, color: #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0.6), text: "未注册用户验证通过后将自动注册")
//            view.addSubview(dLab)
//            dLab.snp.makeConstraints { maker in
//                maker.left.equalTo(.scale*40)
//                maker.top.equalTo(tLab.snp.bottom).offset(.scale*10)
//            }
            
            let bgView = UIView()
            bgView.layer.cornerRadius = .scale*28
            bgView.layer.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0.3)
            view.addSubview(bgView)
            bgView.snp.makeConstraints { m in
                m.width.equalTo(.scale*295)
                m.height.equalTo(.scale*48)
                m.centerX.equalToSuperview()
                m.top.equalTo(.barHeight + .scale*188)
            }
            
            let btn = XS_NoHighlightBtn()
            btn.layer.cornerRadius = .scale*28
            btn.layer.backgroundColor = #colorLiteral(red: 0.1647058824, green: 0.7411764706, blue: 0.6117647059, alpha: 0.6)
            btn.setTitle("获取验证码", for: .normal)
            btn.setTitleColor(#colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), for: .normal)
            btn.titleLabel?.font = .xsFont(name: .regular, .scale*18)
            view.addSubview(btn)
            btn.snp.makeConstraints { m in
                m.width.equalTo(.scale*295)
                m.height.equalTo(.scale*48)
                m.centerX.equalToSuperview()
                m.top.equalTo(bgView.snp.bottom).offset(.scale*24)
            }
            
            let lab = UILabel.xsLabel(size: .scale*18, fontName: .semibold, color: #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0), text: "+86")
            bgView.addSubview(lab)
            lab.snp.makeConstraints { m in
                m.centerX.equalTo(.scale*41)
                m.centerY.equalToSuperview()
            }
            
            let text = NSMutableAttributedString(string: "输入手机号码")
            text.yy_font = .xsFont(name: .regular, .scale*18)
            text.yy_color = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0.6)
            let textField = UITextField()
            textField.attributedPlaceholder = text
            textField.textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
            textField.font = .xsFont(name: .regular, .scale*18)
            bgView.addSubview(textField)
            textField.snp.makeConstraints { m in
                m.edges.equalTo(UIEdgeInsets(top: 0, left: .scale*90, bottom: 0, right: .scale*10))
            }
            
            btn.rx.tap.asDriver()
                .drive(onNext: { [weak self] in
                    textField.resignFirstResponder()
                    guard let text = textField.text, text.xsCheck(.phone) else {
                        self?.view.xsShowMsg("请正确输入手机号")
                        return
                    }
                    let vc = XS_VerificationCodeVC()
                    vc.iosid = self?.iosid
                    vc.openid = self?.openid
                    vc.phone = text
                    self?.navigationController?.pushViewController(vc, animated: true)
                }).disposed(by: disposeBag)
        }
    }

}
